
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

import 'hexcolor.dart';


class MyWebView extends StatefulWidget {
  final  url;
  final  title;
  MyWebView({Key key,@required this.url,@required this.title}) : super (key : key);
  @override
  _MyWebViewState createState() => _MyWebViewState();
}

class _MyWebViewState extends State<MyWebView> {


  FlutterWebviewPlugin flutterWebviewPlugin = FlutterWebviewPlugin();

  double lineProgress = 0.0;

  void initState() {
    super.initState();
    flutterWebviewPlugin.onProgressChanged.listen((progress){
      print(progress);
      setState(() {
        lineProgress = progress;
      });
    });
  }
  @override
  void dispose() {
    flutterWebviewPlugin.dispose();
    super.dispose();
  }



  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      // useWideViewPort: true,

      appBar: AppBar(
        centerTitle: true,
        title: Text(widget.title),
        bottom: PreferredSize(
          child: _progressBar(lineProgress,context),
          preferredSize: Size.fromHeight(3.0),
        ),
      ),
      url: widget.url,
    );
  }

  _progressBar(double progress,BuildContext context) {

    return LinearProgressIndicator(
      backgroundColor: Colors.white70.withOpacity(0),
      value: progress == 1.0 ? 0 : progress,
      valueColor: new AlwaysStoppedAnimation<Color>(HexColor('#567BFD')),
    );
  }

}
